package org.NooLab.nativebrowser.app.controller;

import java.awt.event.WindowEvent;

import javax.swing.JFrame;

import org.NooLab.nativebrowser.browser.BrowserWorker;
import org.NooLab.nativebrowser.components.WebBrowserAppMainIntf;
import org.NooLab.utilities.logging.PrintLog;

import chrriis.dj.nativeswing.swtimpl.NativeInterface;




public class ExitAction extends ExitActionAbstract {
	
	
	
	

	public ExitAction(WebBrowserAppMainIntf app) {
		super(app);
	}

	
	public ExitAction setActionProvider( ExitActionProviderIntf providerIntf){
		exitActionProviderIntf = providerIntf;
		return this;
	}
	
	@Override
	public void doThis(WindowEvent event){
		int r=-1;
		
		if (app!=null){
			// app.setAppIsRunning( false );
		}

		// saving the guidata RequestFocusContext
		if (exitActionProviderIntf!=null){
			r = exitActionProviderIntf.perform(app);
			if (r<0){
				System.err.println("Application denied being closed, since finalization action failed.");
				return ;
			}
		}
		
		
		app.getWebBrowser().removeNotify();
		
		(new BrowserWorker(null, app.getWebBrowser(), "[close]")).execute();
		// app.getWebBrowser().disposeNativePeer();
		PrintLog.Delay(200);
		
		NativeInterface.close() ;
		parentFrame.dispose();
		
		
		System.out.println("Native WebBrowser has been closed (native link and application frame).");
	}
}



